package com.bianguo.android.zsdglide;

import android.graphics.Bitmap;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.bianguo.android.zsdglide.code.Glide;
import com.bianguo.android.zsdglide.listener.RequestListener;

public class MainActivity extends AppCompatActivity implements View.OnClickListener, RequestListener {

    private LinearLayout imageContainer;
    private Button loadBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findView();
    }

    private void findView() {
        imageContainer = findViewById(R.id.main_image_container);
        loadBtn = findViewById(R.id.main_load_btn);
        loadBtn.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.main_load_btn:
                imageContainer.removeAllViews();
                loadImage();
                break;
        }
    }

    private void loadImage() {
        for (int i = 0; i < 60; i++) {
            ImageView iv = new ImageView(this);
            imageContainer.addView(iv, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
            Glide.with(this)
                    .load("http://dn.dengpaoedu.com/glide/" + (i % 66) + ".jpeg")
                    .loading(R.mipmap.ic_launcher)
                    .requestListener(this)
                    .into(iv);
        }
    }

    @Override
    public void onResourceReady(Bitmap bitmap) {

    }

    @Override
    public void onException() {

    }
}
